/*
 * @Author: your name
 * @Date: 2021-12-07 16:22:04
 * @LastEditTime: 2021-12-07 20:12:13
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: /vite_vue3_ts/src/utils/http/axios/axiosTransform.ts
 */
import type { AxiosRequestConfig, AxiosResponse } from 'axios';
import type { RequestOptions, Result } from './types';

export abstract class AxiosTransform {
  /**
   * @description: 请求之前处理配置
   * @param {*}
   * @return {*}
   */
  beforeRequestHook?: (config: AxiosRequestConfig, options: RequestOptions) => AxiosRequestConfig;

  /**
   * @description: 请求成功处理
   * @param {*}
   * @return {*}
   */
  transformRequestData?: (res: AxiosResponse<Result>, options: RequestOptions) => any;

  /**
   * @description: 请求失败处理
   * @param {*}
   * @return {*}
   */
  requestCatch?: (e: Error) => Promise<any>;

  /**
   * @description: 请求之前的拦截器
   * @param {*}
   * @return {*}
   */
  requestInterceptors?: (config: AxiosRequestConfig) => AxiosRequestConfig;

  /**
   * @description: 请求之后的拦截器
   * @param {*}
   * @return {*}
   */
  responseInterceptors?: (config: AxiosResponse<any>) => AxiosResponse<any>;

  /**
   * @description: 请求之前的拦截器错误处理
   * @param {*}
   * @return {*}
   */
  requestInterceptorsCatch?: (error: Error) => void;

  /**
   * @description: 请求之后的拦截器错误处理
   * @param {*}
   * @return {*}
   */
  responseInterceptorsCatch?: (error: Error) => void;
}
